from tqdm import tqdm
import glob
from PIL import Image
from pathlib import Path

import shutil

simdir = Path("H:/data/zzdxOSDB/query_images_2/out/sim/")
maskdir = Path("H:/data/zzdxOSDB/query_images_2/SimImagesMask/")
imagesdir = Path("H:/data/zzdxOSDB/query_images_2/Images/")

src_dir = Path("H:/data/zzdxOSDB/query_images_2/")
outdir = Path("H:/data/zzdxOSDB/query_images_2/out/")

def resize_files():
    index = 0
    for file in tqdm(list(imagesdir.iterdir())):
        fname = file.name

        # maskfile = maskdir / fname
        # maskout = outdir/ "mask" / fname
        # shutil.copy(maskfile,maskout)

        fname = fname.replace(".png",".jpg")
        imagefile = imagesdir / fname
        imgfile = Image.open(imagefile)
        imgw = imgfile.size[0]
        imgh = imgfile.size[1]

        ow = 1024.0 * imgw / imgh 
        ow = int(ow)

        imgfile = imgfile.resize((ow,1024),resample=Image.BILINEAR)
        outfile = outdir / fname
        imgfile.save(outfile)


def copy_files():
    imagesdir = outdir / "images"
    outsimdir = outdir / "simimages"
    src_sim_dir = src_dir/"SimImages"
    src_mask = src_dir/"SimImagesMask"
    out_mask = outdir / "simmasks"

    for file in tqdm(list(imagesdir.iterdir())):
        fname = file.name
        fname = fname.replace(".jpg",".png")

        srcfile = src_sim_dir / fname
        outfile = outsimdir / fname
        shutil.copy(srcfile,outfile)

        srcfile = src_mask / fname
        outfile = out_mask / fname
        shutil.copy(srcfile,outfile)

copy_files()